package com.example.student.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.student.R;
import com.example.student.adapter.DoTaskAdapter;
import com.example.student.adapter.RecordAdapter;
import com.example.student.bean.RecordBean;
import com.example.student.bean.TaskBean;
import com.scwang.smartrefresh.layout.api.RefreshLayout;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
 * 作业记录
 */
public class TaskRecordFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private String TAG = "TaskRecordFragment";
    private View mView;
    private RefreshLayout mPtrLayout;
    private RecyclerView mRecyclerView;
    private RecordAdapter adapter;

    public TaskRecordFragment() {
        Log.e(TAG,"//..TaskRecordFragment。。。Record");
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment TaskRecordFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static TaskRecordFragment newInstance(String param1, String param2) {
        Log.e("TaskRecordFragment","//..TaskRecordFragment。。。newInstance");
        TaskRecordFragment fragment = new TaskRecordFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e(TAG,"//..onCreate。。。Record");
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        Log.e(TAG,"//..onCreateView。。。Record");
        mView =  inflater.inflate(R.layout.fragment_task_record, container, false);
        return  mView;
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initView();
        initData();

    }

    private void initData() {

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        ArrayList mList = new ArrayList<RecordBean>();

        RecordBean bean1 = new RecordBean();
        bean1.setLanguage("五项，全部完成，丢了一项");
        bean1.setTime("2022.5.3");

        RecordBean bean2= new RecordBean();
        bean2.setLanguage("五项，全部完成");
        bean2.setTime("2022.5.4");

        mList.add(bean1);
        mList.add(bean2);

        adapter = new RecordAdapter(getContext(),mList);
        mRecyclerView.setAdapter(adapter);

    }

    private void initView() {

        mPtrLayout = mView.findViewById(R.id.fragment_ptr);
        mRecyclerView = mView.findViewById(R.id.recycle_do);

    }
}